The distribution of C + + variables in memory in the written test often, although simple, but also easy to forget, so make a summary in this to deepen the impression.Write a test program first:
Copy Code code as follows:
#include #include int g_i = 100;
int g_j = 200;
int G_k, g_h;
int main ()
{
const int MAXN = 100;
int *p = (int*) malloc (MAXN * sizeof (int));
static int s_i = 5;
static int s_j = 10;
static int s_k;
static int s_h;
int i = 5;
int j = 10;
int k = 20;
in
Before reading this article, if you don't even know what the stack is, read the basics behind the article first.People who have been exposed to programming know that high-level languages can access data in memory through variable names. So how are these variables stored in memory? How does the program use these variables? The following is an in-depth discussion of this. The C language code below, if not specifically stated, uses the release version compiled by VC by default.First, let's look at
(PBuf), null,null);//Safe release, in order to develop a good coding habits, special to make this macro definition#define GRS_SAFERELEASE (I)if (NULL! = (I)) {(I)->release ();(I) =null; }//Detect if the previous operation was successful#define Grs_com_check (HR,...)if (FAILED (HR)) {grs_printf (__va_args__);goto clear_up; }int_tmain (intARGC, tchar* argv[]) {CoInitialize (NULL);//Create OLE DB init interfaceIDBInitialize *pdbinit = NULL; IDBProperties *pidbproperties = NULL;//Set li
: # Clear the frame pointer register (EBP) # so that once we get into debugging C code, # stack backtraces will be terminated properly. movl $0x0,%ebp # nuke frame pointer # Set the stack pointer movl $(bootstacktop),%esp # now to C code call i386_initThe EBP register has been set to 0 before jumping to the I386_init function. Now it's easy, start implementing the Mon_backtrace function.The experiment provides the READ_EBP () function, which allows us t
strcpy () functionOr a buffer overflow of ret2memcpy. If you are smart and lucky enough, you can apply this technology on your own.For a single free () Bug (free (BUF), the chunk of the Buf can be controlled by users ).
-- [3. n times faster
---- [3.1-Multi-address Overwrite
If you can write more than four bytes, you can not only put the shellcode or jumpcodeAnd can change multiple pointers at the same time to speed up cracking again.
Of course, this requires the write-anything-anywhere permiss
" int_except_handler4 (Pexception_record, Exception_registration*, PCONTEXT, Pexception_record);////////////////////////////////////////////////////////////////////////////displays information about an exception frame and its corresponding scopetablevoidShowsehframe (vc_exception_registration*Pvcexcreg) {BOOL BVcExceptionHandler4= Pvcexcreg->handler = = (Farproc) _except_handler4;//_except_handler4 function of VC if(BVCEXCEPTIONHANDLER4) {//_except_handler4 function of VCprintf"frame:%
snippet, data segment and BSS segment storage variable type * *
#include const int G_A = 10; Code Snippets
int g_b = 20; Data segment
static int g_c = 30; Data segment
static int g_d; BSS segment
int g_e; BSS segment
Char *p1; BSS segment
void Main ()
{
int local_a; Stack
static int local_c = 0; Data segment
static int local_d; Data segment
Char *p3 = "123456"; 123456 in code snippet, p3 on stack
P1 = (char *) malloc (10); Heap, allocated 10 bytes of area in the heap area
strcpy
of the primary table primary keyPretdata = Runsqlgetvalue (piopenrowset,_t ("Select Max (PID) as PMax from T_primary"));if(NULL = = Pretdata) {GotoCLEAR_UP; } IPID = * (int*) ((byte*) Pretdata +sizeof(Dbstatus) +sizeof(ULONG));The //maximum is always 1, so even if a null value is obtained, the starting value is normal 1++ipid; Tableid.ekind = Dbkind_name; TableID.uName.pwszName = (LPOLESTR) pszprimarytable; hr = Piopenrowset->openrowset (Null,tableid, Null,iid_irowsetchange,1, Propset, (i
segmentstatic int g_c = 30; Data segmentstatic int g_d; BSS segmentint g_e; BSS segmentChar *p1; BSS segmentvoid Main (){int local_a; Stackstatic int local_c = 0; Data segmentstatic int local_d; Data segmentChar *p3 = "123456"; 123456 in the code snippet, p3 on the stackP1 = (char *) malloc (10); Heap, allocated 10 bytes of area in the heap areastrcpy (P1, "123456"); 123456{post.content} is placed in a constant area and the compiler may optimize it with the "123456" that P3 points toprintf ("\
first 16-bit value into the 16-bit height of the 32-bit value */LResult = sHighBits;LResult
/* Clear 16-bit low 32-bit values */LResult = 0xFFFF0000;
/* Put the second 16-bit value into the lower 16-bit value of the 32-bit value */LResult | = (long) sLowBits;
Return lResult;}//////////////////////////////////////// /////////
[Problem Discovery]:
Let's take a look at the following test code:
//////////////////////////////////////// /////////Int main (){Short sHighBits1 = 0x7fff;Short sHighBits
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.